package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.excel.ExcelUtil;
import com.gfxy.modules.items.entity.Lxspy;
import com.gfxy.modules.items.entity.Zyyxsztsjh;
import com.gfxy.modules.items.mapper.LxspyMapper;
import com.gfxy.modules.items.mapper.ZyyxsztsjhMapper;
import com.gfxy.modules.items.service.ILxspyService;
import com.gfxy.modules.items.vo.LxspyMemberPage;
import com.gfxy.modules.items.vo.ZyyxsztsjhMemberPage;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 留学生培养
 * @Author: jeecg-boot
 * @Date:   2023-12-26
 * @Version: V1.0
 */
@Service
public class LxspyServiceImpl extends AbstractProjectServiceImpl<LxspyMapper, Lxspy> implements ILxspyService {

	public LxspyServiceImpl() {
		this.memberCellNum = 5;
	}

	@Override
	public IPage<LxspyMemberPage> selectListPage(String date, Integer pageNo, Integer pageSize) {
		Page<LxspyMemberPage> page = new Page<>(pageNo, pageSize);
		Page<LxspyMemberPage> page1 = page.setRecords(baseMapper.selectMemberPageListByYear(date));
		return page1;
	}

	@Override
	public List<LxspyMemberPage> getMemberPageListByYear(String date) {
		return baseMapper.selectMemberPageListByYear(date);
	}

	@Override
	public Double getTotalScore(Lxspy lxspy) {
		Integer type = lxspy.getType();
		Integer kind = lxspy.getKind();
		Integer studentNum = lxspy.getStudentNumber();
		double result = 0;
		if(type == 1){
			if(kind == 1){
				//线下
				result = studentNum * 40;
			} else if(kind == 2){
				result = studentNum * 20;
			}
		} else if (type == 2){
			if(kind == 1){
				result = studentNum * 10;
			} else if(kind == 2){
				result = studentNum * 5;
			}
		}
		return result;
	}

	@Override
	protected Lxspy getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));
		String type = ExcelUtil.formatCell(row.getCell(1));
		String kind = ExcelUtil.formatCell(row.getCell(2));
		String studentNumber = ExcelUtil.formatCell(row.getCell(3));
		String projectName = ExcelUtil.formatCell(row.getCell(4));
		Lxspy lxspy = new Lxspy();
		lxspy.setDate(date);
		lxspy.setType(this.translateType(type));
		lxspy.setKind(this.translateKind(kind));
		lxspy.setStudentNumber(Integer.parseInt(studentNumber));
		lxspy.setProjectName(projectName);
		lxspy.setTotalScore(this.getTotalScore(lxspy));

		return lxspy;
	}

	private Integer translateKind(String kind) {
		if(kind == null || kind.equals("")){
			return 0;
		} else if(kind.equals("线下")){
			return 1;
		} else if(kind.equals("线上")){
			return 2;
		}else {
			return 0;
		}
	}

	private Integer translateType(String type) {
		if(type == null || type.equals("")){
			return 0;
		} else if(type.equals("学历留学生")){
			return 1;
		} else if(type.equals("各类短期培养")){
			return 2;
		}else {
			return 0;
		}
	}
}
